/**
 * @(#) Stock.java
 */

package edu.stthomas.edu.seis770.stocksystem;

import java.util.ArrayList;
import java.util.List;
import java.util.Observable;

public class Stock extends Observable {
    private List<StockStatus> stats;
    private StockStatus currentStockStatus;
    private String stockSymbol;

    protected Stock(String stockSymbol, StockStatus stockStatus) {
        addObserver(EventManager.getUniqueInstance());
        stats = new ArrayList<StockStatus>();
        this.stockSymbol = stockSymbol;
        this.currentStockStatus = stockStatus;
        stats.add(currentStockStatus);
        setChanged();
        notifyObservers(EventManager.STOCK_CREATE_EVENT);

    }

    public static Stock createStock(String stockSymbol, StockStatus stockStatus) {
        Stock newStock = new Stock(stockSymbol, stockStatus);
        return newStock;
    }
    public void addStatus(StockStatus stockStatus) {
        stats.add(stockStatus);
        currentStockStatus = stockStatus;
        setChanged();
        notifyObservers(EventManager.STOCK_UPDATE_EVENT);

    }

    public StockStatus getCurrentStockStatus() {
        return currentStockStatus;
    }

    public List<StockStatus> getStockStats() {
        return stats;
    }

    public String getStockSymbol() {
        return stockSymbol;
    }
    
    public String toString() {
    	String stockString = "Stock Symbol: " + stockSymbol 
    				+ "\t Current Price: " + getCurrentStockStatus().getPrice().getFormattedAmount() 
    				+ "\t Last Update: "
    				+ getCurrentStockStatus().getDate();
    	return stockString;
    }


}
